package com.wg.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wg.R;
import com.wg.entity.Achievements;
import com.wg.mapper.AchievementMapper;
import com.wg.service.AchievementService;
import com.wg.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class AchievementServiceImpl extends ServiceImpl<AchievementMapper, Achievements> implements AchievementService {

    @Autowired
    UserService userService;

    @Override
    public R getAchievementByUser(Integer userId) {
        LambdaQueryWrapper<Achievements> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Achievements::getUserId, userId);
        List<Achievements> ach = list(wrapper);
        ach = ach.stream().map(a -> a.setUserName(userService.getById(userId).getName())).collect(Collectors.toList());
        return R.ok(ach);
    }
}
